#!/bin/bash

function ShowUsage {
    echo -e "\n\033[32;1m$0 [init|run]\033[0m"
}

function Quit {
    [ -n "$1" ] && echo -e "\n\033[31;1m ERROR: $1!\033[0m"
    exit 1
}

function InitializePV {
    cd /opt/pv || Quit
    for dir in tomcat_app tomcat_log; do
        mkdir -p $dir || Quit
        chown -R tomcat7.tomcat7 $dir || Quit
    done
}

# Start
case "$*" in
    '')
        InitializePV
        /usr/share/tomcat7/bin/catalina.sh run
        ;;
    'init')
        InitializePV
        ;;
    'run')
        /usr/share/tomcat7/bin/catalina.sh run
        ;;
    *)
        ShowUsage
        Quit "Unknown arguments \"$*\""
        ;;
esac

